﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;

namespace BOH.DataManagement
{
    public partial class DictManage : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDict();
                string DictID = string.Empty;
                if (Request.QueryString["ID"] != null)
                {
                    DictID = Request.QueryString["ID"].ToString();
                    LoadDataDictByID(DictID);
                }

                
            }
        }

        public void LoadDataDictByID(string dictID)
        {
            DataSet dst = DictManageClass.LoadDataDictByID(dictID);
            this.drpDict.SelectedValue = dst.Tables[0].Rows[0]["dict_name"].ToString();
            txtDictData.Text = dst.Tables[0].Rows[0]["dict_Value"].ToString();
            txtDictDisplay.Text = dst.Tables[0].Rows[0]["dict_Display"].ToString();
            drpDictStatus.SelectedValue = dst.Tables[0].Rows[0]["dict_status"].ToString();
            txtDictNote.Text = dst.Tables[0].Rows[0]["dict_note"].ToString();
        }


        /// <summary>
        /// 获取字典下拉数据
        /// </summary>
        public void LoadDict()
        {
            drpDict.Items.Clear();

            DataSet dst = DictManageClass.LoadAdict();

            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                ListItem list = new ListItem( dr["dict_display"].ToString(),dr["dict_value"].ToString());
                drpDict.Items.Add(list);
            }

        }

        protected void butSave_Click(object sender, EventArgs e)
        {
            
            string dictName = drpDict.SelectedValue;
            string dictValue = txtDictData.Text;
            string dictDisplay = txtDictDisplay.Text;
            string dictStatus = drpDictStatus.SelectedValue;
            string dictNote = txtDictNote.Text;
            if (Request.QueryString["ID"]==null)
            {
               DictManageClass.InsertDataDict(dictStatus, dictValue, dictName, dictDisplay, dictNote);
            }
            else
            {
                string strID = Request.QueryString["ID"].ToString();
                DictManageClass.UpdateSysDataDict(dictStatus, dictValue, dictName, dictDisplay, dictNote, strID);
            }
            Response.Redirect("DictManageList.aspx?dict="+Request.QueryString["dict"].ToString());
        }
    }
}
